﻿Imports System.IO

Public Class RecordMessage
    Inherits MessageBase

    Public Property TimeStamp As DateTime?
    Public Property PositionLatitude As Integer?
    Public Property PositionLongitude As Integer?
    Public Property Altitude As Decimal?
    Public Property HeartRate As Integer?
    Public Property Cadence As Integer?
    Public Property Distance As Decimal?
    Public Property Speed As Decimal?
    Public Property Power As Integer?
    Public Property CompressedSpeedDistance As Byte()
    Public Property Grade As Decimal?
    Public Property Resistance As Integer?
    Public Property TimeFromCourse As Decimal?
    Public Property CycleLength As Decimal?
    Public Property Temperature As Integer?

    Protected Overrides Sub Populate(reader As System.IO.BinaryReader, Definition As DefinitionMessage)
        For Each FieldDef As FieldDefinition In Definition.Fields
            Select Case FieldDef.FieldDefinitionNumber
                Case 253 ' Timestamp
                    TimeStamp = FitHelper.TranslateDateTime(reader.ReadUInt32)
                Case 0 'PositionLatitude
                    PositionLatitude = reader.ReadInt32()
                Case 1 'PositionLongitude
                    PositionLongitude = reader.ReadInt32()
                Case 2 'Altitude
                    Altitude = CDec(reader.ReadUInt16() / 2) - 500
                Case 3 'HeartRate
                    HeartRate = reader.ReadByte()
                Case 4 'Cadence
                    Cadence = reader.ReadByte()
                Case 5 'Distance
                    Distance = CDec(reader.ReadUInt32() / 100)
                Case 6 'Speed
                    Speed = CDec(reader.ReadUInt16() / 1000)
                Case 7 'Power
                    Power = reader.ReadUInt16()
                Case 8 'CompressedSpeedDistance
                    CompressedSpeedDistance = reader.ReadBytes(3)
                Case 9 'Grade
                    Grade = CDec(reader.ReadInt16() / 100)
                Case 10 'Resistance
                    Resistance = reader.ReadByte()
                Case 11 'TimeFromCourse
                    TimeFromCourse = CDec(reader.ReadInt32() / 1000)
                Case 12 'CycleLength
                    CycleLength = CDec(reader.ReadByte() / 100)
                Case 13 'Temperature
                    Temperature = reader.ReadByte()
                Case Else
                    FitHelper.ReadUnknownField(reader, FieldDef)
            End Select
        Next
    End Sub
End Class
